/**
 * 应付台账明细
 */
/**
 * 表单自定义控制器
 */
app.controller('btnCtrl', ['$scope', '$http', BtnController]);
function BtnController($scope, $http) {
	$scope.bindBtn = function(event) {
		switch(event){
			case 'event-to-add': // 新增
			{

				$scope.subGrid.sonlist.push({state : 0,transferStatus : 0});

				break;
			}
			case 'event-to-delete': // 删除选中数据
			{
				$scope.subGrid.deleteBatch();
				break;
			}
		};
	}

}


app.controller('formSelfCtrl', ['$scope', '$http', FormSelfController]);
function FormSelfController($scope, $http){

	/*
	 * 数字框变动
	 */
	$scope.subGrid.numberChange = function(row, field) {
		var index = row.index;
		if (field == 'costPrice' || field == 'quantity' || field == 'proxyPrice') {//单价 、数量、 代理价

			var costPrice = 0;
			var quantity = 0;
			var proxyPrice = 0;
			if($scope.subGrid.sonlist[index]['costPrice']) costPrice = $scope.subGrid.sonlist[index]['costPrice'];
			if($scope.subGrid.sonlist[index]['quantity']) quantity = $scope.subGrid.sonlist[index]['quantity'];
			if($scope.subGrid.sonlist[index]['proxyPrice']) proxyPrice = $scope.subGrid.sonlist[index]['proxyPrice'];

			var totalPrice = parseFloat(costPrice) * parseFloat(quantity);
			var proxyTotalPrice = parseFloat(proxyPrice) * parseFloat(quantity);

			$scope.subGrid.sonlist[index]['totalPrice'] = totalPrice.toFixed(2);
			$scope.subGrid.sonlist[index]['proxyTotalPrice'] = proxyTotalPrice.toFixed(2);

		}
	}
}



app.controller('formSelfCtrl', ['$scope', '$http', FormSelfController]);
function FormSelfController($scope, $http){

	$scope.changeValueMap = function(field) {
		if(field == 'unitPrice' || field == 'quantity' || field == 'proxyPrice'){
			var costPrice = parseFloat( $scope.valueMap["costPrice"]); // 成本价
			var quantity = parseFloat( $scope.valueMap["quantity"]); // 数量
			var proxyPrice = parseFloat( $scope.valueMap["proxyPrice"]); // 代理价

			if((costPrice || costPrice==0) && (quantity || quantity==0)){
				var totalPrice = costPrice*quantity;
				$scope.valueMap['totalPrice'] = totalPrice.toFixed(2);
			}
			if((quantity || quantity==0) && (proxyPrice || proxyPrice==0)){
				var proxyTotalPrice = proxyPrice*quantity;
				$scope.valueMap['proxyTotalPrice'] = proxyTotalPrice.toFixed(2);
			}
		}
	}

}


